<?php
// 测试修复后的API

echo "测试修复后的API...\n";

// 构造请求
$url = 'http://yingyang.com/api/food_ingredient/batchGetDishInfo';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/x-www-form-urlencoded',
]);
curl_setopt($ch, CURLOPT_TIMEOUT, 65); // 设置超时时间为65秒

echo "发送请求到: " . $url . "\n";

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);

echo "HTTP状态码: " . $httpCode . "\n";
echo "CURL错误: " . $error . "\n";
echo "响应内容: " . $response . "\n";

curl_close($ch);

if ($response) {
    $data = json_decode($response, true);
    if ($data) {
        echo "\n解析后的数据:\n";
        print_r($data);
    } else {
        echo "\nJSON解析失败\n";
    }
} else {
    echo "\n无响应内容\n";
}

echo "\n测试完成\n";
?>